package com.centriole.service.workflow.service.parse.component;

/**
 * 对应json数据中的  "properties":{ ... } , 如果是一个多任务节点的Property,则其成员变量tasks集合不为空
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Property {

    private String id;
    private String type;
    private String radioId;
    private String fkId;
    private String fkType;
    private String nextNodeId;
    private List<Task> tasks = new ArrayList<>();
    private Map<String,String> condition = new HashMap<>();
    private Integer allowStop;
    private Integer allowRecall;
    private Integer allowHang;
    private String agreeNodeId;
    private String disagreeNodeId;
    
    public Property(){}

    public Property(String id, String type) {
        this.id = id;
        this.type = type;
    }
    
    //TODO:删除一些构造方法
    public Property(String id, String radioId, String type, String fkId, String fkType, String nextNodeId) {
        this.id = id;
        this.radioId = radioId;
        this.type = type;
        this.fkId = fkId;
        this.fkType = fkType;
        this.nextNodeId = nextNodeId;
    }
    
    public Property(String id, String type, String radioId, String fkId, String fkType, String nextNodeId, Integer allowStop, Integer allowRecall, Integer allowHang) {
		this.id = id;
		this.type = type;
		this.radioId = radioId;
		this.fkId = fkId;
		this.fkType = fkType;
		this.nextNodeId = nextNodeId;
		this.allowStop = allowStop;
		this.allowRecall = allowRecall;
		this.allowHang = allowHang;
	}
     
	public Property(String id, String type, String radioId, String fkId, String fkType, String nextNodeId, Integer allowStop, Integer allowRecall, Integer allowHang, String agreeNodeId, String disagreeNodeId) {
		this.id = id;
		this.type = type;
		this.radioId = radioId;
		this.fkId = fkId;
		this.fkType = fkType;
		this.nextNodeId = nextNodeId;
		this.allowStop = allowStop;
		this.allowRecall = allowRecall;
		this.allowHang = allowHang;
		this.agreeNodeId = agreeNodeId;
		this.disagreeNodeId = disagreeNodeId;
	}

	public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRadioId() {
        return radioId;
    }

    public void setRadioId(String radioId) {
        this.radioId = radioId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getFkId() {
        return fkId;
    }

    public void setFkId(String fkId) {
        this.fkId = fkId;
    }

    public String getFkType() {
        return fkType;
    }

    public void setFkType(String fkType) {
        this.fkType = fkType;
    }

    public String getNextNodeId() {
        return nextNodeId;
    }

    public void setNextNodeId(String nextNodeId) {
        this.nextNodeId = nextNodeId;
    }

    public Map<String, String> getCondition() {
        return condition;
    }

    public void setCondition(Map<String, String> condition) {
        this.condition = condition;
    }

    public List<Task> getTasks() {
        return tasks;
    }

    public void setTasks(List<Task> tasks) {
        this.tasks = tasks;
    }

    public Integer getAllowStop() {
		return allowStop;
	}

	public void setAllowStop(Integer allowStop) {
		this.allowStop = allowStop;
	}

	public Integer getAllowRecall() {
		return allowRecall;
	}

	public void setAllowRecall(Integer allowRecall) {
		this.allowRecall = allowRecall;
	}

	public Integer getAllowHang() {
		return allowHang;
	}

	public void setAllowHang(Integer allowHang) {
		this.allowHang = allowHang;
	}

	public String getAgreeNodeId() {
		return agreeNodeId;
	}

	public void setAgreeNodeId(String agreeNodeId) {
		this.agreeNodeId = agreeNodeId;
	}

	public String getDisagreeNodeId() {
		return disagreeNodeId;
	}

	public void setDisagreeNodeId(String disagreeNodeId) {
		this.disagreeNodeId = disagreeNodeId;
	}
	
	
	
	@Override
    public String toString() {
        if(tasks.size() > 0){
            return "Property{" +
                    "id='" + id + '\'' +
                    ", type='" + type + '\'' +
                    ", tasks=" + tasks +
                    '}';
        }
        return "Property{" +
                "id='" + id + '\'' +
                ", type='" + type + '\'' +
                ", radioId='" + radioId + '\'' +
                ", fkId='" + fkId + '\'' +
                ", fkType='" + fkType + '\'' +
                ", nextNodeId='" + nextNodeId + '\'' +
                ", condition=" + condition +
                ", agreeNodeId=" + agreeNodeId +
                ", disagreeNodeId=" + disagreeNodeId +
                '}';
    }

	
	
	
    /**
     * 转换为Map("node1-node2, msg==1"这种格式的条件map),每个condition都需要解析成线条链接
     * @return
     */
    public Map<String,String> getCondtionMap(){
        Map<String,String> conditionMap = new HashMap<>();
        this.condition.entrySet().parallelStream().forEach(e->{
            conditionMap.put( id+ "-" +e.getKey() ,e.getValue());
        });
        return conditionMap;
    }
    

	/**
     * 
     *  功   能：对应json数据中的  "properties":{ "multiTaskNode:"{"tasks":{ ... } }} , 
     *  创建人：陈默晗
     *  时   间：2018年1月3日下午2:43:39
     */
    public class Task{
        private String id;
        private String name;
        private String radioId;
        private String fkId;
        private String fkType;
        private String nextNodeId;
        private String preCondition;            //前置条件,开始条件
        private Map<String,String> condtions = new HashMap<>();

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getRadioId() {
            return radioId;
        }

        public void setRadioId(String radioId) {
            this.radioId = radioId;
        }

        public String getFkId() {
            return fkId;
        }

        public void setFkId(String fkId) {
            this.fkId = fkId;
        }

        public String getFkType() {
            return fkType;
        }

        public void setFkType(String fkType) {
            this.fkType = fkType;
        }

        public String getNextNodeId() {
            return nextNodeId;
        }

        public void setNextNodeId(String nextNodeId) {
            this.nextNodeId = nextNodeId;
        }

        public String getPreCondition() {
            return preCondition;
        }

        public void setPreCondition(String preCondition) {
            this.preCondition = preCondition;
        }

        public Map<String, String> getCondition() {
            return condtions;
        }

        public void setCondition(Map<String, String> condition) {
            this.condtions = condition;
        }
        
        public Integer getAllowStop() {
			return allowStop;
		}


		public Integer getAllowRecall() {
			return allowRecall;
		}



		public Integer getAllowHang() {
			return allowHang;
		}


		public Task(){}

        public Task(String id, String name, String radioId, String fkId, String fkType, String nextNodeId) {
            this.id = id;
            this.name = name;
            this.radioId = radioId;
            this.fkId = fkId;
            this.fkType = fkType;
            this.nextNodeId = nextNodeId;
        }
 
		public Task(String id, String name, String radioId, String fkId, String fkType, String nextNodeId, String preCondition) {
			super();
			this.id = id;
			this.name = name;
			this.radioId = radioId;
			this.fkId = fkId;
			this.fkType = fkType;
			this.nextNodeId = nextNodeId;
			this.preCondition = preCondition;
		}

		@Override
        public String toString() {
            return "Task{" +
                    "id='" + id + '\'' +
                    ", name='" + name + '\'' +
                    ", radioId='" + radioId + '\'' +
                    ", fkId='" + fkId + '\'' +
                    ", fkType='" + fkType + '\'' +
                    ", nextNodeId='" + nextNodeId + '\'' +
                    ", preCondition='" + preCondition + '\'' +
                    ", condition=" + condtions +
                    '}';
        }
    }
}
